import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../helper/Helper.dart';
import '../helper/downloadHelper.dart';
import '../helper/fileHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ImageWidget extends StatefulWidget {
  @override
  ImageWidget(this.guid);
  final String guid;

  @override
  createState() => new ImageWidgetState();
}

class ImageWidgetState extends State<ImageWidget> {
//  定义底部导航列表
  bool isLoading = true;
  late File img;

  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    getImgFile();
  }

  Future getImgFile() async {
    var file1 =
        await Helper.fileCache.getSingleFile(Helper.GetImgUrl2(widget.guid));

    // if(!mounted)return;
    setState(() {
      img = file1;
      isLoading = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return isLoading == true
        ? Center(
            child: SpinKitCircle(
            color: Colors.blue,
          ))
        : Image.file(
            img,
            fit: BoxFit.contain,
          );
  }
}
